package com.zretc.device.ui;

import java.awt.BorderLayout;
import java.awt.FlowLayout;

import javax.swing.JButton;
import javax.swing.JDialog;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;

import com.zretc.device.dao.Device_NeedDao;
import com.zretc.device.entity.Device_Need;

import javax.swing.JTextField;
import java.awt.Font;
import javax.swing.JLabel;
import javax.swing.JOptionPane;

import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;

public class Device_needFindUserDialog extends JDialog {

	private final JPanel contentPanel = new JPanel();
	private JTextField txtneed_id;
	private JTextField txtdepartment;
	private JTextField txtdevice_code;
	private JTextField txtneed_num;
	private JTextField txtbegin_date;
	private JTextField txtend_date;
	private JTextField txtneed_person;
	private JTextField txtneed_tele;

	/**
	 * Launch the application.
	 */
	public static void main(String[] args) {
		try {
			Device_needFindUserDialog dialog = new Device_needFindUserDialog();
			dialog.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
			dialog.setVisible(true);
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	/**
	 * Create the dialog.
	 */
	public Device_needFindUserDialog() {
		setBounds(100, 100, 803, 524);
		getContentPane().setLayout(new BorderLayout());
		contentPanel.setBorder(new EmptyBorder(5, 5, 5, 5));
		getContentPane().add(contentPanel, BorderLayout.CENTER);
		contentPanel.setLayout(null);
		
		txtneed_id = new JTextField();
		txtneed_id.setFont(new Font("宋体", Font.PLAIN, 25));
		txtneed_id.setColumns(10);
		txtneed_id.setBounds(299, 66, 250, 30);
		contentPanel.add(txtneed_id);
		
		JLabel label = new JLabel("需求订单查询");
		label.setFont(new Font("宋体", Font.PLAIN, 40));
		label.setBounds(236, 13, 250, 47);
		contentPanel.add(label);
		
		JLabel label_1 = new JLabel("请输入订单号");
		label_1.setFont(new Font("宋体", Font.PLAIN, 25));
		label_1.setBounds(129, 66, 156, 30);
		contentPanel.add(label_1);
		
		JLabel label_2 = new JLabel("使用部门");
		label_2.setFont(new Font("宋体", Font.PLAIN, 25));
		label_2.setBounds(165, 109, 120, 30);
		contentPanel.add(label_2);
		
		txtdepartment = new JTextField();
		txtdepartment.setEditable(false);
		txtdepartment.setFont(new Font("宋体", Font.PLAIN, 25));
		txtdepartment.setColumns(10);
		txtdepartment.setBounds(299, 109, 250, 30);
		contentPanel.add(txtdepartment);
		
		JLabel label_3 = new JLabel("设备编号");
		label_3.setFont(new Font("宋体", Font.PLAIN, 25));
		label_3.setBounds(165, 155, 120, 30);
		contentPanel.add(label_3);
		
		txtdevice_code = new JTextField();
		txtdevice_code.setEditable(false);
		txtdevice_code.setFont(new Font("宋体", Font.PLAIN, 25));
		txtdevice_code.setColumns(10);
		txtdevice_code.setBounds(299, 155, 250, 30);
		contentPanel.add(txtdevice_code);
		
		JLabel label_4 = new JLabel("需求数量");
		label_4.setFont(new Font("宋体", Font.PLAIN, 25));
		label_4.setBounds(165, 198, 120, 30);
		contentPanel.add(label_4);
		
		txtneed_num = new JTextField();
		txtneed_num.setEditable(false);
		txtneed_num.setFont(new Font("宋体", Font.PLAIN, 25));
		txtneed_num.setColumns(10);
		txtneed_num.setBounds(299, 198, 250, 30);
		contentPanel.add(txtneed_num);
		
		JLabel label_5 = new JLabel("起始日期");
		label_5.setFont(new Font("宋体", Font.PLAIN, 25));
		label_5.setBounds(165, 241, 133, 30);
		contentPanel.add(label_5);
		
		txtbegin_date = new JTextField();
		txtbegin_date.setEditable(false);
		txtbegin_date.setFont(new Font("宋体", Font.PLAIN, 25));
		txtbegin_date.setColumns(10);
		txtbegin_date.setBounds(299, 241, 250, 30);
		contentPanel.add(txtbegin_date);
		
		txtend_date = new JTextField();
		txtend_date.setEditable(false);
		txtend_date.setFont(new Font("宋体", Font.PLAIN, 25));
		txtend_date.setColumns(10);
		txtend_date.setBounds(299, 284, 250, 30);
		contentPanel.add(txtend_date);
		
		JLabel label_6 = new JLabel("结束日期");
		label_6.setFont(new Font("宋体", Font.PLAIN, 25));
		label_6.setBounds(165, 284, 106, 30);
		contentPanel.add(label_6);
		
		JLabel label_7 = new JLabel("用 户 名");
		label_7.setFont(new Font("宋体", Font.PLAIN, 25));
		label_7.setBounds(165, 327, 106, 30);
		contentPanel.add(label_7);
		
		txtneed_person = new JTextField();
		txtneed_person.setEditable(false);
		txtneed_person.setFont(new Font("宋体", Font.PLAIN, 25));
		txtneed_person.setColumns(10);
		txtneed_person.setBounds(299, 327, 250, 30);
		contentPanel.add(txtneed_person);
		
		txtneed_tele = new JTextField();
		txtneed_tele.setEditable(false);
		txtneed_tele.setFont(new Font("宋体", Font.PLAIN, 25));
		txtneed_tele.setColumns(10);
		txtneed_tele.setBounds(299, 370, 250, 30);
		contentPanel.add(txtneed_tele);
		
		JLabel label_8 = new JLabel("用户电话");
		label_8.setFont(new Font("宋体", Font.PLAIN, 25));
		label_8.setBounds(165, 370, 133, 30);
		contentPanel.add(label_8);
		
		JButton button = new JButton("查询");
		button.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				String tneed_id=txtneed_id.getText();
				//转型
				int need_id = Integer.parseInt(tneed_id);
				Device_NeedDao dnd = new Device_NeedDao();
				//调用查询的方法
				Device_Need dn=dnd.findDevNeedById(need_id);
				
				if (dn==null) {
					// 弹窗提示
					JOptionPane.showMessageDialog(null, "该单号不存在");
				}else {
					//赋值
					txtdepartment.setText(dn.getDepartment());
					txtdevice_code.setText(dn.getDevice_code());
					txtneed_num.setText(Integer.toString(dn.getNeed_num()));
					txtbegin_date.setText(dn.getBegin_date());
					txtend_date.setText(dn.getEnd_date());
					txtneed_person.setText(dn.getNeed_person());
					txtneed_tele.setText(dn.getNeed_tele());
				}
				
				
			}
		});
		button.setFont(new Font("宋体", Font.PLAIN, 25));
		button.setBounds(583, 62, 124, 38);
		contentPanel.add(button);
		
		JButton button_1 = new JButton("取消");
		button_1.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				//赋值
				txtneed_id.setText("");
				txtdepartment.setText("");
				txtdevice_code.setText("");
				txtneed_num.setText("");
				txtbegin_date.setText("");
				txtend_date.setText("");
				txtneed_person.setText("");
				txtneed_tele.setText("");
			}
		});
		button_1.setFont(new Font("宋体", Font.PLAIN, 25));
		button_1.setBounds(583, 125, 124, 38);
		contentPanel.add(button_1);
		//居中
		setLocationRelativeTo(null);
	}
}
